home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
c
/
bor_ti.exe
/
TI1157.ASC
< prev
next >
Wrap
Text File
|
1992-11-11
|
4KB
|
199 lines
PRODUCT : Borland C++ NUMBER : 1157
VERSION : 3.1
OS : DOS
DATE : November 11, 1992 PAGE : 1/3
TITLE : Determining Extended Memory Size from CMOS.
/* -------------------[ ACCESSING CMOS DATA ]------------------------ *\
The AT CMOS RAM can be accessed through ports 70H ( Control/Address )
and 71h( CMOS Data ). When reading CMOS RAM, one must:
1. Disable interrupts.
( This ensures that no interruption takes place between
items 2. and 4. listed below ).
2. Write the offset of the CMOS RAM data to be fetched to I/O
port 70h.
3. Given the increasing speed of CPUs, it may be necessary to
create a delay between items 2. and 4. The simplest way to
achieve the delay is via a 'jmp' instruction:
asm jmp short $+2
Include the '#pragma inline' directive in the source code when
using the above so that the assembler ( TASM by default ) may
process the 'jmp'. Alternatively a 'goto/Label:' combination
or an '__emit__()' statement may also be used.
4. Read the Data ( a byte ) from port 71h.
5. ReEnable Interrupts.
Writing to CMOS RAM is similar to the process above:
1. Disable Interrupts.
2. Write the CMOS RAM offset which is to be written to port 70h.
3. Create a delay.
4. Write the data byte to port 71h.
Note that step 3. may not be necessary on some older machines. Below
is a function which given two offsets for a low and high order byte
will return the word value stored in the CMOS. This can be easily
modified to write a word to the CMOS RAM.
\* -------------------[ ACCESSING CMOS DATA ]------------------------ */
PRODUCT : Borland C++ NUMBER : 1157
VERSION : 3.1
OS : DOS
DATE : November 11, 1992 PAGE : 2/3
TITLE : Determining Extended Memory Size from CMOS.
/* ----------------------------------------------------------------- *\
| |
| This function will fetch a word from the cmos given the low byte |
| offset and high byte offset in the cmos. |
| |
\* ----------------------------------------------------------------- */
#include <dos.h>
#include <stdio.h>
#pragma inline
const int CMOS_PORT_WRITE = 0x70;
const int CMOS_PORT_READ = 0x71;
unsigned get_cmos( unsigned char low, unsigned char high );
int main()
{
unsigned ext; /* Extended memory in Kilobytes */
ext = get_cmos( 0x30, 0x31 );/* Get extended detected during POST */
printf( "Installed extended memory detected by POST: %8uk\n", ext );
return( 0 );
}
unsigned get_cmos( unsigned char low, unsigned char high )
{
unsigned word;
unsigned char *p;
unsigned char l,h;
p = ( unsigned char *) &word;
disable();
outportb( CMOS_PORT_WRITE, high );
asm jmp short $+2
h = inportb( CMOS_PORT_READ );
outportb( CMOS_PORT_WRITE, low );
asm jmp short $+2
l = inportb( CMOS_PORT_READ );
PRODUCT : Borland C++ NUMBER : 1157
VERSION : 3.1
OS : DOS
DATE : November 11, 1992 PAGE : 3/3
TITLE : Determining Extended Memory Size from CMOS.
*p = l;
*(p+1) = h;
enable();
return word;
}
DISCLAIMER: You have the right to use this technical information subject
to the terms of the No-Nonsense License Statement that you received with
the Borland product to which this information pertains.